//
//  ViewController.m
//  DevicePrepaireReportViewThreeController
//
//  Created by MacBook Pro on 16/8/1.
//  Copyright © 2016年 guotongbo. All rights reserved.
//
//屏幕的宽
#define SCREENW self.view.bounds.size.width
//屏幕的高
#define SCREENH self.view.bounds.size.height
#define Margin 5
#define LineLen 1;
// RGB颜色
#define TBColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]

#import "DevicePrepaireReportThreeViewController.h"
#import "BorderButton.h"
#import "NrowLabelMessage.h"
#import "NrowLabelViewCell.h"
#import "RSCheckBox.h"
#import "RSCheckGroup.h"
#import "MyButton.h"
#import "TouchView.h"

@interface DevicePrepaireReportThreeViewController ()<UITableViewDelegate,UITableViewDataSource,UIPickerViewDelegate,UIPickerViewDataSource>
/**邮箱*/
@property(nonatomic,strong)UIButton *emailBtn;
/**邮箱线*/
@property(nonatomic,strong)UIView *emailLine;
/**邮件地址Label*/
@property(nonatomic,strong)UILabel *emailLabel;
/**保存*/
@property(nonatomic,strong)BorderButton *saveBtn;
/**tableView*/
@property(nonatomic,strong)UITableView *tableV;
/**数据*/
@property(nonatomic,strong)NSArray *info;
/**区头*/
@property(nonatomic,strong)NSMutableDictionary *header;
/**产品名称数组*/
@property(nonatomic,strong)NSArray *productNameArr;
/**产品名称Btn*/
@property(nonatomic,strong)UIButton *productNameBtn;
/**产品名称字符串*/
@property(nonatomic,strong)NSString *productNameStr;
/**单选按钮类型View*/
@property(nonatomic,strong)UIPickerView *singleView;
/**区脚View*/
@property(nonatomic,strong)UIView *footView;
/**增加的间距*/
@property(nonatomic,assign)NSInteger addMargin;
/**新增服务记录的Y*/
@property(nonatomic,assign)NSInteger addServeRecordY;
/**邮箱textField*/
@property(nonatomic,strong) UITextField *emailTF;
@property(nonatomic,strong)UIView *addView;
@end

@implementation DevicePrepaireReportThreeViewController
/**邮箱*/
@synthesize emailBtn;
/**邮箱线*/
@synthesize emailLine;
/**邮件地址Label*/
@synthesize emailLabel;
/**保存*/
@synthesize saveBtn;
/**tableView*/
@synthesize tableV;
/**数据容器*/
@synthesize info;
/**区头*/
@synthesize header;
/**产品名称数组*/
@synthesize productNameArr;
/**产品名称Btn*/
@synthesize productNameBtn;
/**产品名称字符串*/
@synthesize productNameStr;
/**单选按钮类型View*/
@synthesize singleView;
/**区脚View*/
@synthesize footView;
/**增加的间距*/
@synthesize addMargin;
/**服务记录的Y*/
@synthesize addServeRecordY;
/**邮箱textField*/
@synthesize emailTF;



- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设备维修单";
    self.view.backgroundColor = [UIColor whiteColor];
    //取数据
    [self GetData];
    //搭建界面
    [self setUpInterface];
    //改变导航栏的颜色、字体
    [self initNav];
    
}
-(void)initNav{
    
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:93/255.0 green:199/255.0 blue:255/255.0 alpha:1.0]];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    
}

//取数据
-(void)GetData{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"DevicePrepaireReportThreeViewController" ofType:@"plist"];
    info = [NSArray arrayWithContentsOfFile:path];
    
    header = [NSMutableDictionary dictionary];
}
//搭建界面
-(void)setUpInterface{
    
    //top和下面的按钮
    [self setUpBaseInfo];
    tableV = [[UITableView alloc]initWithFrame:CGRectMake(0,emailLine.frame.origin.y + 2 , SCREENW, saveBtn.frame.origin.y - emailLine.frame.origin.y + 1)style:UITableViewStyleGrouped];
    tableV.separatorStyle = NO;
    tableV.delegate = self;
    tableV.dataSource = self;
    
    //tableV.style = UITableViewStyleGrouped;
    [self.view addSubview:tableV];
    // 设置额外滚动区域
    //tableV.contentInset = UIEdgeInsetsMake(0, 0, 50, 0);
}

//基本信息
-(void)setUpBaseInfo{
    //邮箱
    emailBtn = [[UIButton alloc]init];
    [emailBtn setImage:[UIImage imageNamed:@"c_7"] forState:UIControlStateNormal];
    CGFloat emailBtnX = SCREENW - 45;
    CGFloat emailBtnY = 69;
    CGFloat emailBtnW = 32;
    CGFloat emailBtnH = 32;
    emailBtn.frame = CGRectMake(emailBtnX, emailBtnY, emailBtnW, emailBtnH);
    [emailBtn addTarget:self action:@selector(sendEmail) forControlEvents:UIControlEventTouchUpInside ];
    
    [self.view addSubview:emailBtn];
    
    //邮箱线
    emailLine = [[UIView alloc]init];
    emailLine.backgroundColor = TBColor(212, 212, 212, 1);
    CGFloat emailLineX = 0;
    CGFloat emailLineY = emailBtnY + emailBtnH + Margin;
    CGFloat emailLineW = SCREENW;
    CGFloat emailLineH = LineLen;
    emailLine.frame = CGRectMake(emailLineX, emailLineY, emailLineW, emailLineH);
    [self.view addSubview:emailLine];
    
    //保存
    saveBtn = [BorderButton buttonWithType:UIButtonTypeCustom];
    saveBtn.backgroundColor = TBColor(5, 206, 114, 1);
    CGFloat saveBtnX = 1;
    CGFloat saveBtnY = SCREENH - 64;
    CGFloat saveBtnW = SCREENW;
    CGFloat saveBtnH = 64;
    saveBtn.frame = CGRectMake(saveBtnX, saveBtnY, saveBtnW, saveBtnH);
    [saveBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [self.view addSubview:saveBtn];
    
    UILabel *titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, 69, SCREENW - emailBtnW - 20, emailBtnH)];
    titleL.font = [UIFont boldSystemFontOfSize:17];
    titleL.text = @"            产品应用培训报告";
    titleL.textColor = [UIColor blackColor];
    titleL.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:titleL];
}
//点击邮件事件
-(void)sendEmail{
    
    UIView *emailView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    emailView.tag = 7;
    emailView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:emailView];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(18, SCREENW / 3, SCREENW - 36, 150)];
    view.layer.backgroundColor = TBColor(94, 204, 250, 1).CGColor;
    view.layer.borderWidth = 1;
    view.backgroundColor = [UIColor whiteColor];
    [emailView addSubview:view];
    
    emailLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, SCREENW - 105, 30)];
    emailLabel.text = @"请输入邮箱地址:";
    [view addSubview:emailLabel];
    
    emailTF = [[UITextField alloc]initWithFrame:CGRectMake(25, 40, SCREENW * 4/5, 30)];
    emailTF.backgroundColor = TBColor(212, 212, 212, 1);
    [view addSubview:emailTF];
    
    UILabel *textMargin = [[UILabel alloc]initWithFrame:CGRectMake(20, 40, 5, 30)];
    textMargin.backgroundColor = TBColor(212, 212, 212, 1);
    [view addSubview:textMargin];
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW * 4/5 - 80, 90, 80, 30)];
    [btn setTitle:@"发送" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    btn.backgroundColor = TBColor(102, 85, 191, 1);
    [btn addTarget:self action:@selector(sendE) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(40, 90, 80, 30)];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    cancelBtn.backgroundColor = TBColor(102, 85, 191, 1);
    [cancelBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:cancelBtn];
    
}

//点击取消按钮
-(void)cancel{
    UIView *subViews = [self.view viewWithTag:7];
    [subViews removeFromSuperview];
}

//点击发送邮件按钮
-(void)sendE{
    
    UIApplication *app = [UIApplication sharedApplication];
    NSURL *url = [NSURL URLWithString:emailTF.text];
    //[app openURL:url];
    UIView *subViews = [self.view viewWithTag:7];
    [subViews removeFromSuperview];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return info.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSArray *groupInfo = info[section][@"info"];
    return groupInfo.count;
}
#pragma mark 创建每一行的cell
//给cell赋值
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //根据类创建cell
    NrowLabelViewCell *cell = [NrowLabelViewCell NrowLabelMessageViewWithTableView:tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //根据行号取出模型，赋值
    NSString *str =info[indexPath.section][@"info"][indexPath.row];
    NSLog(@"%@",str);
    cell.infoLabel.text =info[indexPath.section][@"info"][indexPath.row];
    
    return  cell;
}
//设置cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 82;
}
//设置区头
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW - 30, 50)];
    view.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(8, 0, SCREENW - 16, 50)];
    label.font = [UIFont boldSystemFontOfSize:17];
    label.text =[NSString stringWithFormat:@"  %@", info[section][@"header"]];
    
    [view addSubview:label];
    if (section == 1||section == 5|| section == 6 || section == 7) {
        //产品名称（单选）
        if (section == 1) {
            productNameArr = [NSArray arrayWithObjects:@"Bact/ALERT 3D 60",@"Bact/ALERT 3D 120",@"Bact/ALERT 3D 240",@"PREVI Color Gram 12",@"PREVI Color Gram 30",@"MINI VIDAS",@"VIDAS 30",@"VIDAS 3",@"VITEK MS IVD",@"VITEK MS RUO（鉴定",@"VITEK MS RUO（建库）",@"VITEK 2",@"VITEK 2 XL",@"VITEK 2 COMPACT 15",@"VITEK 2 COMPACT  30",@"VITEK 2 COMPACT  60",@"手工试剂", nil];
            productNameBtn = [[UIButton alloc]initWithFrame:CGRectMake(18, 40, SCREENW - 36, 35)];
            [productNameBtn setTitle:productNameStr forState:UIControlStateNormal];
            [productNameBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            productNameBtn.layer.borderColor = TBColor(202, 202, 202, 1).CGColor;
            productNameBtn.layer.borderWidth = 2;
            [productNameBtn addTarget:self action:@selector(productNameClick) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:productNameBtn];
            
        }
        
        label.textColor = [UIColor blackColor];
        //左边的线
        UIView *leftL = [[UIView alloc]initWithFrame:CGRectMake(8, 0, 2, 82)];
        leftL.backgroundColor = TBColor(143, 143, 143, 1);
        //右边的线
        
        UIView *rightL = [[UIView alloc]initWithFrame:CGRectMake(SCREENW - 10, 0, 2, 82)];
        rightL.backgroundColor = TBColor(143, 143, 143, 1);
        
        [view addSubview:leftL];
        [view addSubview:rightL];
        return view;
        
    }
    else{
        label.textColor = TBColor(102, 85, 191, 1);
        label.layer.borderColor = TBColor(102, 85, 191, 1).CGColor;
        label.layer.borderWidth = 1;
        
        //左边的线
        UIView *leftL = [[UIView alloc]initWithFrame:CGRectMake(8, 0, 2, 50)];
        leftL.backgroundColor = TBColor(143, 143, 143, 1);
        //右边的线
        
        UIView *rightL = [[UIView alloc]initWithFrame:CGRectMake(SCREENW - 10, 0, 2, 50)];
        rightL.backgroundColor = TBColor(143, 143, 143, 1);
        
        [view addSubview:leftL];
        [view addSubview:rightL];
        
        
        [view addSubview:label];
        return view;
        
    }
    
    return view;

    
}
//设置区尾View
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 441)];
    footView.backgroundColor = [UIColor whiteColor];
   
    if (section == 0 || section == 2) {
        //左边的线
        UIView *lefLL = [[UIView alloc]initWithFrame:CGRectMake(8, 0, 2, 164)];
        lefLL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:lefLL];
        //右边的线
        UIView *rightL = [[UIView alloc]initWithFrame:CGRectMake(SCREENW - 10, 0, 2, 164)];
        rightL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:rightL];
    }
    //产品名称（单选）
    if (section == 1) {
        //左边的线
        UIView *lefLL = [[UIView alloc]initWithFrame:CGRectMake(8, 0, 2, 164)];
        lefLL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:lefLL];
        //右边的线
        UIView *rightL = [[UIView alloc]initWithFrame:CGRectMake(SCREENW - 10, 0, 2, 164)];
        rightL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:rightL];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 19, 156, 21)];
        label.text = @"注明";
        label.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:label];
        
        UITextField *textF = [[UITextField alloc]initWithFrame:CGRectMake(18, 42, SCREENW - 40, 30)];
        textF.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:textF];
        
        UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, 156, 21)];
        labelTwo.text = @"设备序列号*:";
        labelTwo.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:labelTwo];
        
        UITextField *textFTwo =[[UITextField alloc]initWithFrame:CGRectMake(18, 123, SCREENW - 40, 30)];
        textFTwo.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:textFTwo];
        
        return footView;
        
    }
    //培训人员记录
    if (section == 3) {
        //左边的线
        UIView *lefLL = [[UIView alloc]initWithFrame:CGRectMake(8, 0, 2, 50)];
        lefLL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:lefLL];
        //右边的线
        UIView *rightL = [[UIView alloc]initWithFrame:CGRectMake(SCREENW - 10, 0, 2, 50)];
        rightL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:rightL];
        
        UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(18, 15, 40, 20)];
        [leftBtn setTitle:@"新增" forState:UIControlStateNormal];
        [leftBtn setTitleColor:TBColor(102, 206, 114, 1) forState:UIControlStateNormal];
        [leftBtn addTarget:self action:@selector(addClick) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:leftBtn];
        
        UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW - 60, 15, 40, 20)];
        [rightBtn setTitleColor:TBColor(102, 206, 114, 1) forState:UIControlStateNormal];
        [rightBtn addTarget:self action:@selector(delClick) forControlEvents:UIControlEventTouchUpInside];
        
        [rightBtn setTitle:@"删除" forState:UIControlStateNormal];
        [footView addSubview:rightBtn];
        
    }
    //培训内容记录
    if (section == 4) {
        //左边的线
        UIView *lefLL = [[UIView alloc]initWithFrame:CGRectMake(8, 0, 2, 335)];
        lefLL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:lefLL];
        //右边的线
        UIView *rightL = [[UIView alloc]initWithFrame:CGRectMake(SCREENW - 10, 0, 2, 335)];
        rightL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:rightL];
        //产品介绍
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 14, 282, 21)];
        label.text = @"产品介绍*：";
        label.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:label];
        
        UITextView *textV = [[UITextView alloc]initWithFrame:CGRectMake(21, 45, SCREENW - 42, 30)];
        textV.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:textV];
        //耗材介绍
        UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(20, 89, 282, 21)];
        labelTwo.text = @"耗材介绍*：";
        labelTwo.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:labelTwo];
        
        UITextView *textVTwo = [[UITextView alloc]initWithFrame:CGRectMake(21,124, SCREENW - 42, 30)];
        textVTwo.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:textVTwo];
        
        //操作流程
        UILabel *labelThree = [[UILabel alloc]initWithFrame:CGRectMake(20, 168, 282, 21)];
        labelThree.text = @"操作流程*：";
        labelThree.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:labelThree];
        
        UITextView *textVThree = [[UITextView alloc]initWithFrame:CGRectMake(21,199, SCREENW - 42, 30)];
        textVThree.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:textVThree];
        
        //质量控制
        UILabel *labelFour = [[UILabel alloc]initWithFrame:CGRectMake(20, 243, 282, 21)];
        labelFour.text = @"质量控制*：";
        labelFour.font = [UIFont boldSystemFontOfSize:17];
        [footView addSubview:labelFour];
        
        UITextView *textVFour = [[UITextView alloc]initWithFrame:CGRectMake(21,274, SCREENW - 42, 30)];
        textVFour.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:textVFour];

    }
    //问题处理
    if (section == 5) {
        //左边的线
        UIView *lefLL = [[UIView alloc]initWithFrame:CGRectMake(8, 0, 2, 50)];
        lefLL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:lefLL];
        //右边的线
        UIView *rightL = [[UIView alloc]initWithFrame:CGRectMake(SCREENW - 10, 0, 2, 50)];
        rightL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:rightL];
        
        //问题处理
        MyButton *questionHandleBtn = [MyButton buttonWithType:UIButtonTypeCustom];
        questionHandleBtn.frame = CGRectMake(18, 0, SCREENW - 40, 30);
      
        [questionHandleBtn setTitle:@"常见问题、原因和处理方法" forState:UIControlStateNormal];
        [questionHandleBtn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
        [questionHandleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        questionHandleBtn.layer.borderColor = TBColor(212, 212, 212, 1).CGColor;
        questionHandleBtn.layer.borderWidth = 1;
        [questionHandleBtn addTarget:self action:@selector(questionHandleClick:) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:questionHandleBtn];
        
    }
    //系统的维护
    if (section == 6) {
        //左边的线
        UIView *lefLL = [[UIView alloc]initWithFrame:CGRectMake(8, 0, 2, 50)];
        lefLL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:lefLL];
        //右边的线
        UIView *rightL = [[UIView alloc]initWithFrame:CGRectMake(SCREENW - 10, 0, 2, 50)];
        rightL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:rightL];
        
        //系统的维护
        MyButton *systemDefendBtn = [MyButton buttonWithType:UIButtonTypeCustom];
        systemDefendBtn.frame = CGRectMake(18, 0, SCREENW - 40, 30);
        [systemDefendBtn setTitle:@"定期的维护内容及方法" forState:UIControlStateNormal];
        [systemDefendBtn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
        [systemDefendBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        systemDefendBtn.layer.borderColor = TBColor(212, 212, 212, 1).CGColor;
        systemDefendBtn.layer.borderWidth = 1;
        [systemDefendBtn addTarget:self action:@selector(systemDefendClick:) forControlEvents:UIControlEventTouchUpInside];
        [footView addSubview:systemDefendBtn];
        
    }
    //其他重要的培训内容（填写）
    if (section == 7) {
        //左边的线
        UIView *lefLL = [[UIView alloc]initWithFrame:CGRectMake(8, 0, 2, 140)];
        lefLL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:lefLL];
        //右边的线
        UIView *rightL = [[UIView alloc]initWithFrame:CGRectMake(SCREENW - 10, 0, 2, 140)];
        rightL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:rightL];
        
        //底部的线
        UIView *bottomL = [[UIView alloc]initWithFrame:CGRectMake(8, 140, SCREENW - 16, 2)];
        bottomL.backgroundColor =TBColor(160, 160, 160, 1);
        [footView addSubview:bottomL];
        UITextView *textV = [[UITextView alloc]initWithFrame:CGRectMake(21,0, SCREENW - 42, 120)];
        textV.backgroundColor = TBColor(202, 202, 202, 1);
        [footView addSubview:textV];

    }
    return  footView;
}
//问题处理点击事件
-(void)questionHandleClick:(UIButton *)btn{

    btn.selected = !btn.selected;
    if (btn.selected) {
        [btn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
        
    }else{
        [btn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
    }
    
   
}
//系统维护点击事件
-(void)systemDefendClick:(UIButton *)btn{
    btn.selected = !btn.selected;
    if (btn.selected) {
        [btn setImage:[UIImage imageNamed:@"checkbox1_unchecked"] forState:UIControlStateNormal];
        
    }else{
        [btn setImage:[UIImage imageNamed:@"checkbox1_checked"] forState:UIControlStateNormal];
    }

    
}
-(void)addClick{
    NSLog(@"点击增加");
    //第一,插入数据源
    self.addView = [[UIView alloc]initWithFrame:CGRectMake(0, addServeRecordY, 320, 100)];
    self.addView.backgroundColor = [UIColor grayColor];
    //UIView *footView = (UIView *)[self.view viewWithTag:4];
    [footView addSubview:self.addView];
    
    addServeRecordY = addServeRecordY + 150 + addMargin;
    
    [tableV reloadData];
    
}

//产品名称点击事件生成View
-(void)productNameClick{
    NSLog(@"设备点击了");
    
    UIView *bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    bigView.backgroundColor = [UIColor clearColor];
    bigView.tag = 8;
    [self.view addSubview:bigView];
    
    singleView = [[UIPickerView alloc]initWithFrame:CGRectMake(10, SCREENH - saveBtn.bounds.size.height - 150, SCREENW - 20, 150)];
    singleView.tag = 1;
    singleView.backgroundColor = [UIColor whiteColor];
    singleView.delegate = self;
    singleView.dataSource = self;
    [bigView addSubview:singleView];
    
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
        return productNameArr.count;
}
#pragma mark pickerView代理方法
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    return productNameArr[row];
    
}
// pickerView滚动结束时调用
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (singleView.tag == 1) {
        [productNameBtn setTitle:productNameArr[row] forState:UIControlStateNormal];
        productNameStr = productNameArr[row];
        UIView *subviews  = [self.view viewWithTag:1];
        [subviews removeFromSuperview];
    }
    
}
//区头高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return 82;
    }
    if (section == 5 || section == 6) {
        return 50;
    }
    return 50;
    
}
//区尾的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 3 ) {
        return 50;
    }else if (section == 1){
        return 165;
    }else if (section == 4){
        return 320;
    }else if (section == 7){
        return 150;
    }else if (section == 5 || section == 6){
        return 40;
    }else if(section == 0 || section == 2){
        
        return 0;

    }
    return 0;
}

@end
